import Compression from 'vite-plugin-compression'

export function viteCompression(env) {
  const { VITE_BUILD_COMPRESS } = env

  let plugin = null

  if (VITE_BUILD_COMPRESS) {
    if (VITE_BUILD_COMPRESS === 'gzip') {
      plugin = Compression({
        ext: '.gz',
        algorithm: 'gzip',
        deleteOriginFile: false,
      })
    }

    if (VITE_BUILD_COMPRESS === 'brotli') {
      plugin = Compression({
        ext: '.br',
        algorithm: 'brotliCompress',
        deleteOriginFile: false,
      })
    }
  }

  return plugin
}
